package me.ljd.yigo.service;

import java.util.ArrayList;

import com.bokesoft.yigo.common.def.ScriptType;
import com.bokesoft.yigo.common.util.TypeConvertor;
import com.bokesoft.yigo.mid.base.DefaultContext;
import com.bokesoft.yigo.mid.parser.BaseMidFunctionImpl;
import com.bokesoft.yigo.mid.service.IExtService;
import com.bokesoft.yigo.parser.IExecutor;
/**
 * 测试表达式
 * <ExtService>
 * 		<Service Name="TestFormulaService" Description="测试表达式" Impl="me.ljd.yigo.formula.TestFormulaService"/>				
 *	</ExtService>
 * @author USER
 *
 */
public class TestFormulaService extends BaseMidFunctionImpl implements IExtService {
	//private MidCo

	@Override
	public Object doCmd(DefaultContext context, ArrayList<Object> paras) throws Throwable {
		return handle(context, paras.toArray());
	}

	@Override
	public Object evalImpl(String name, DefaultContext context, Object[] args, IExecutor executor) throws Throwable {
		return handle(context, args);
	}
	public Object handle(DefaultContext context, Object[] args) throws Throwable {
		if(args.length<1) return null;
		String formula = TypeConvertor.toString(args[0]);
		System.out.println(formula);
		Object result = context.getMidParser().eval(ScriptType.Formula, formula);
		return result;
	}
}
